package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseUser;
import com.briup.mt.bean.BaseUserExample;
import com.briup.mt.dao.BaseUserMapper;
import com.briup.mt.service.IBaseUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseUserImpl implements IBaseUserService {

    @Resource
    private BaseUserMapper baseUserMapper;

    @Override
    public void saveOrUpdate(BaseUser baseUser) {
        if(baseUser.getId()==null){
            baseUserMapper.insert(baseUser);
        }
        else
        {
            baseUserMapper.updateByPrimaryKey(baseUser);
        }
    }

    @Override
    public void deleteById(long id) {
        baseUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<BaseUser> query(String username){
        BaseUserExample example = new BaseUserExample();
        if(!StringUtils.isEmpty(username)){
            example.createCriteria().andUsernameLike("%"+username+"%");
        }
        List<BaseUser> list = baseUserMapper.selectByExample(example);
        return list;
    }
}
